<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useGoodsStore } from '../stores/goods'

const router = useRouter()
const goodsStore = useGoodsStore()

// 主打产品数据
const featuredProduct = ref({
  title: 'iPhone 16 Pro',
  subtitle: '钛金属。超坚韧。超轻盈。',
  description: '创新之外，更进一步。',
  image:
    'https://images.unsplash.com/photo-1695048133142-1a20484d2569?w=800&h=600&fit=crop&q=80',
  ctaText: '进一步了解',
  buyText: '购买'
})

// 第二个主打产品
const secondProduct = ref({
  title: 'MacBook Air',
  subtitle: '天蓝色上新，M4 性能冲天。',
  description: '强力处理，轻薄设计。',
  image:
    'https://images.unsplash.com/photo-1541807084-5c52b6b3adef?w=800&h=600&fit=crop&q=80',
  ctaText: '进一步了解',
  buyText: '购买'
})

// 产品系列数据
const productSeries = ref([
  {
    id: 1,
    name: 'iPad Pro',
    tagline: '强大性能，创意无限',
    image:
      'https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?w=600&h=400&fit=crop&q=80',
    type: '平板电脑'
  },
  {
    id: 2,
    name: 'Apple Watch',
    tagline: '健康生活的完美伙伴',
    image:
      'https://images.unsplash.com/photo-1434494878577-86c23bcb06b9?w=600&h=400&fit=crop&q=80',
    type: '智能手表'
  },
  {
    id: 3,
    name: 'AirPods Pro',
    tagline: '主动降噪，沉浸音质',
    image:
      'https://images.unsplash.com/photo-1606220945770-b5b6c2c55bf1?w=600&h=400&fit=crop&q=80',
    type: '音频产品'
  },
  {
    id: 4,
    name: 'Mac Studio',
    tagline: '专业性能，桌面工作站',
    image:
      'https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=600&h=400&fit=crop&q=80',
    type: '台式电脑'
  }
])

// Apple 特色服务
const appleServices = ref([
  {
    id: 1,
    title: 'Apple Pay',
    description: '便捷安全的支付体验',
    icon: '💳',
    bgColor: 'linear-gradient(135deg, #007AFF 0%, #0056CC 100%)'
  },
  {
    id: 2,
    title: 'iCloud',
    description: '你的内容，安全同步',
    icon: '☁️',
    bgColor: 'linear-gradient(135deg, #34C759 0%, #30A952 100%)'
  },
  {
    id: 3,
    title: 'Apple Care',
    description: '专业技术支持服务',
    icon: '🛡️',
    bgColor: 'linear-gradient(135deg, #FF9500 0%, #FF8C00 100%)'
  },
  {
    id: 4,
    title: 'Apple Store',
    description: '线上线下购物体验',
    icon: '🏪',
    bgColor: 'linear-gradient(135deg, #AF52DE 0%, #9A42C5 100%)'
  }
])

// 特色亮点
const highlights = ref([
  {
    id: 1,
    title: '隐私保护',
    subtitle: '力保个人信息安全，这很 iPhone。',
    image:
      'https://images.unsplash.com/photo-1563986768494-4dee2763ff3f?w=800&h=500&fit=crop&q=80',
    darkTheme: true
  },
  {
    id: 2,
    title: '创新技术',
    subtitle: '学什么专业，Mac 都专业。',
    image:
      'https://images.unsplash.com/photo-1531297484001-80022131f5a1?w=800&h=500&fit=crop&q=80',
    darkTheme: false
  }
])

// 方法
const goToProduct = (type: string) => {
  router.push({
    path: '/goods',
    query: { productType: type }
  })
}

const learnMore = (product: string) => {
  console.log('了解更多:', product)
}

const buyNow = (product: string) => {
  console.log('购买:', product)
}

// 生命周期
onMounted(() => {
  // 可以在这里加载产品数据
})
</script>

<template>
  <div class="home">
    <!-- 主要 Hero 区域 -->
    <section class="main-hero">
      <div class="hero-content">
        <h1 class="hero-title">{{ featuredProduct.title }}</h1>
        <p class="hero-subtitle">{{ featuredProduct.subtitle }}</p>
        <p class="hero-description">{{ featuredProduct.description }}</p>
        <div class="hero-actions">
          <button
            class="cta-link"
            @click="learnMore(featuredProduct.title)"
          >
            {{ featuredProduct.ctaText }}
          </button>
          <button
            class="buy-link"
            @click="buyNow(featuredProduct.title)"
          >
            {{ featuredProduct.buyText }}
          </button>
        </div>
      </div>
      <div class="hero-visual">
        <img
          :src="featuredProduct.image"
          :alt="featuredProduct.title"
        />
      </div>
    </section>

    <!-- 第二个产品展示 -->
    <section class="secondary-hero">
      <div class="hero-content">
        <h2 class="hero-title">{{ secondProduct.title }}</h2>
        <p class="hero-subtitle">{{ secondProduct.subtitle }}</p>
        <div class="hero-actions">
          <button
            class="cta-link"
            @click="learnMore(secondProduct.title)"
          >
            {{ secondProduct.ctaText }}
          </button>
          <button
            class="buy-link"
            @click="buyNow(secondProduct.title)"
          >
            {{ secondProduct.buyText }}
          </button>
        </div>
      </div>
      <div class="hero-visual">
        <img
          :src="secondProduct.image"
          :alt="secondProduct.title"
        />
      </div>
    </section>

    <!-- 产品系列网格 -->
    <section class="product-grid">
      <div class="grid-container">
        <div
          v-for="product in productSeries"
          :key="product.id"
          class="product-tile"
          @click="goToProduct(product.type)"
        >
          <div class="tile-content">
            <h3 class="tile-title">{{ product.name }}</h3>
            <p class="tile-tagline">{{ product.tagline }}</p>
            <div class="tile-actions">
              <span class="learn-more">进一步了解</span>
              <span class="buy-now">购买</span>
            </div>
          </div>
          <div class="tile-image">
            <img
              :src="product.image"
              :alt="product.name"
            />
          </div>
        </div>
      </div>
    </section>

    <!-- 特色亮点 -->
    <section class="highlights">
      <div
        v-for="highlight in highlights"
        :key="highlight.id"
        class="highlight-tile"
        :class="{ 'dark-theme': highlight.darkTheme }"
      >
        <div class="highlight-content">
          <h3 class="highlight-title">{{ highlight.title }}</h3>
          <p class="highlight-subtitle">{{ highlight.subtitle }}</p>
          <button class="highlight-cta">进一步了解</button>
        </div>
        <div class="highlight-image">
          <img
            :src="highlight.image"
            :alt="highlight.title"
          />
        </div>
      </div>
    </section>

    <!-- Apple 服务 -->
    <section class="apple-services">
      <div class="section-container">
        <div class="section-header">
          <h2 class="section-title">Apple 生态服务</h2>
          <p class="section-subtitle">一体化的数字生活体验</p>
        </div>

        <div class="services-grid">
          <div
            v-for="service in appleServices"
            :key="service.id"
            class="service-card"
            :style="{ background: service.bgColor }"
          >
            <div class="service-icon">{{ service.icon }}</div>
            <h3 class="service-title">{{ service.title }}</h3>
            <p class="service-description">{{ service.description }}</p>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
.home {
  background-color: #f5f5f7;
}

/* 主要 Hero 区域 */
.main-hero {
  background: linear-gradient(135deg, #1d1d1f 0%, #2d2d2f 100%);
  color: white;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  position: relative;
  overflow: hidden;
}

.main-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(
    circle,
    rgba(0, 122, 255, 0.1) 0%,
    transparent 50%
  );
  animation: float 20s ease-in-out infinite;
}

.hero-content {
  flex: 1;
  max-width: 500px;
  z-index: 2;
  position: relative;
}

.hero-title {
  font-size: clamp(48px, 8vw, 96px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
  background: linear-gradient(135deg, #ffffff 0%, #007aff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: clamp(24px, 4vw, 40px);
  font-weight: 600;
  line-height: 1.1;
  margin-bottom: 16px;
  opacity: 0.9;
}

.hero-description {
  font-size: 21px;
  font-weight: 400;
  line-height: 1.4;
  margin-bottom: 40px;
  opacity: 0.8;
}

.hero-actions {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
}

.hero-visual {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 2;
}

.hero-visual img {
  max-width: 100%;
  height: auto;
  max-height: 600px;
  object-fit: contain;
  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.3));
  animation: levitate 6s ease-in-out infinite;
}

/* 第二个产品展示 */
.secondary-hero {
  background: linear-gradient(135deg, #f5f5f7 0%, #ffffff 100%);
  color: #1d1d1f;
  padding: 80px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 1200px;
  margin: 0 auto;
  gap: 60px;
}

.secondary-hero .hero-title {
  background: linear-gradient(135deg, #1d1d1f 0%, #007aff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 按钮样式 */
.cta-link,
.buy-link {
  font-size: 17px;
  font-weight: 400;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  text-decoration: none;
  display: inline-block;
}

.cta-link {
  background: transparent;
  color: #007aff;
  border: 1px solid #007aff;
}

.cta-link:hover {
  background: #007aff;
  color: white;
  transform: translateY(-2px);
}

.buy-link {
  background: #007aff;
  color: white;
}

.buy-link:hover {
  background: #0056cc;
  transform: translateY(-2px);
}

.main-hero .cta-link {
  color: white;
  border-color: rgba(255, 255, 255, 0.6);
}

.main-hero .cta-link:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: white;
}

/* 产品网格 */
.product-grid {
  padding: 80px 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.product-tile {
  background: white;
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  min-height: 400px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.product-tile:hover {
  transform: translateY(-8px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
}

.tile-content {
  padding: 40px 30px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  position: relative;
  z-index: 2;
}

.tile-title {
  font-size: 32px;
  font-weight: 700;
  color: #1d1d1f;
  margin-bottom: 8px;
  line-height: 1.1;
}

.tile-tagline {
  font-size: 19px;
  color: #86868b;
  margin-bottom: 20px;
  line-height: 1.4;
}

.tile-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.learn-more,
.buy-now {
  font-size: 17px;
  color: #007aff;
  cursor: pointer;
  transition: color 0.3s ease;
}

.learn-more:hover,
.buy-now:hover {
  color: #0056cc;
}

.tile-image {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  height: 50%;
  overflow: hidden;
  opacity: 0.1;
  transition: opacity 0.3s ease;
}

.product-tile:hover .tile-image {
  opacity: 0.2;
}

.tile-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 特色亮点 */
.highlights {
  padding: 60px 20px;
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.highlight-tile {
  background: white;
  border-radius: 18px;
  overflow: hidden;
  min-height: 500px;
  display: flex;
  align-items: center;
  padding: 60px;
  gap: 60px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.highlight-tile:hover {
  transform: scale(1.02);
}

.highlight-tile.dark-theme {
  background: #1d1d1f;
  color: white;
}

.highlight-content {
  flex: 1;
}

.highlight-title {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 16px;
  line-height: 1.1;
}

.highlight-subtitle {
  font-size: 24px;
  font-weight: 400;
  margin-bottom: 30px;
  line-height: 1.3;
  opacity: 0.8;
}

.highlight-cta {
  background: #007aff;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 17px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.highlight-cta:hover {
  background: #0056cc;
  transform: translateY(-2px);
}

.highlight-image {
  flex: 1;
  max-width: 400px;
}

.highlight-image img {
  width: 100%;
  height: auto;
  border-radius: 12px;
}

/* Apple 服务 */
.apple-services {
  background: #f5f5f7;
  padding: 80px 20px;
}

.section-container {
  max-width: 1200px;
  margin: 0 auto;
}

.section-header {
  text-align: center;
  margin-bottom: 60px;
}

.section-title {
  font-size: 48px;
  font-weight: 700;
  color: #1d1d1f;
  margin-bottom: 16px;
  line-height: 1.1;
}

.section-subtitle {
  font-size: 21px;
  color: #86868b;
  line-height: 1.4;
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.service-card {
  padding: 40px 30px;
  border-radius: 18px;
  text-align: center;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.service-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.service-icon {
  font-size: 48px;
  margin-bottom: 20px;
}

.service-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 12px;
}

.service-description {
  font-size: 17px;
  opacity: 0.9;
  line-height: 1.4;
}

/* 动画 */
@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(180deg);
  }
}

@keyframes levitate {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20px);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-hero,
  .secondary-hero {
    flex-direction: column;
    text-align: center;
    gap: 40px;
  }

  .hero-actions {
    justify-content: center;
    gap: 20px;
  }

  .highlight-tile {
    flex-direction: column;
    padding: 40px 30px;
    gap: 30px;
    text-align: center;
  }

  .services-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .section-title {
    font-size: 36px;
  }

  .highlight-title {
    font-size: 36px;
  }
}

@media (max-width: 480px) {
  .hero-title {
    font-size: 48px;
  }

  .hero-subtitle {
    font-size: 24px;
  }

  .tile-title {
    font-size: 24px;
  }

  .section-title {
    font-size: 28px;
  }

  .highlight-title {
    font-size: 28px;
  }

  .highlight-subtitle {
    font-size: 19px;
  }
}
</style>
